package com.fp.m7.client.view;

import net.customware.gwt.presenter.client.widget.WidgetDisplay;

import com.fp.m7.client.presenter.AppPresenter;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * This is where all the application layout is done. This is why the header bar is at the top, beneath there is a info
 * events popup bar, and the main contents.
 * 
 * @author 7
 */
public class AppView<T> extends Composite implements AppPresenter.Display {

    private final SimplePanel headerPlaceHolder;
    private final SimplePanel contentPlaceHolder;
    private final VerticalPanel infoPanel;

    private Widget content;
    private Widget header;

    public AppView() {
        VerticalPanel panel = new VerticalPanel();
        panel.addStyleName("centered");

        headerPlaceHolder = new SimplePanel();
        panel.add(headerPlaceHolder);

        infoPanel = new VerticalPanel();
        infoPanel.addStyleName("infoPopupContainer");
        panel.add(infoPanel);
        
        contentPlaceHolder = new SimplePanel();
        contentPlaceHolder.addStyleName("mainContent");
        panel.add(contentPlaceHolder);

        initWidget(panel);
    }

    @Override
    public void setContent(WidgetDisplay display) {
        if (content != null) {
            contentPlaceHolder.remove(content);
        }
        content = display.asWidget();
        contentPlaceHolder.add(content);
    }

    @Override
    public void setHeader(WidgetDisplay display) {
        if (header != null) {
            headerPlaceHolder.remove(header);
        }
        header = display.asWidget();
        headerPlaceHolder.add(header);
    }

    @Override
    public HasWidgets getInfoPanel() {
        return infoPanel;
    }

}
